package com.bookmall.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Squking on 2018/5/14.
 */
public class Order {
    private int orderNum;
    private String logname;
    private List<Book> listBook = new ArrayList<>();
    private float sum;
    private String orderContent;

    public int getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(int orderNum) {
        this.orderNum = orderNum;
    }

    public String getLogname() {
        return logname;
    }

    public void setLogname(String logname) {
        this.logname = logname;
    }

    public List<Book> getListBook() {
        return listBook;
    }

    public void addBook(Book book) {
        this.listBook.add(book);
    }

    public String listBook2contentString()
    {
        StringBuilder builder = new StringBuilder();
        int size = listBook.size();
        for (int i = 0; i < size; i++) {
            builder.append("ISBN:");
            builder.append(listBook.get(i).getISBN() + " ");
            builder.append("书名:");
            builder.append(listBook.get(i).getName() + " ");
            builder.append("作者:");
            builder.append(listBook.get(i).getAuthor() + " ");
            builder.append("出版社:");
            builder.append(listBook.get(i).getPublish() + " ");
            builder.append("价格:");
            builder.append(listBook.get(i).getPrice() + " ");
            if (i < size - 1)
            {
                builder.append("\n");
            }
        }
        return builder.toString();
    }

    public float getSum() {
        return sum;
    }

    public void setSum(float sum) {
        this.sum = sum;
    }

    public String getOrderContent() {
        return orderContent;
    }

    public void setOrderContent(String orderContent) {
        this.orderContent = orderContent;
    }

    public void recalcSum()
    {
        sum = 0;
        for (int i = listBook.size() - 1; i >= 0; i--) {
            sum += listBook.get(i).getPrice();
        }
    }
}
